﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using AssetFrame.BP;
using AssetFrame.Message;
using Newtonsoft.Json.Linq;
using SysFrame.BP;
using SysFrame.Message;
using System.Data;

namespace AppServer.Controllers.Asset
{
    [Route("api/[controller]")]
    [ApiController]
    public class AssetA2Controller : SysControllerBase
    {
        // 资产分类
        // POST: api/AssetA2
        [HttpPost]
        public ActionResult<string> Post([FromBody] dynamic data)
        {
            string jsTimeStamp = data.jsTimeStamp;
            string Action = data.Action == null ? "Get" : data.Action;
            string rtstr = "";
            //得到列表
            if (Action == "Get")
            {
                rtstr = Get(data);
            }
            //if (Action == "Save")
            //{
            //    rtstr = Save(data);
            //}
            return rtstr;
        }

        /// <summary>
        /// 得到选择的值
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Get(dynamic data)
        {
            JObject postdata = JObject.FromObject(data.data);
            MsQuery msq = new MsQuery();
            if (msq == null)
            {
                msq = new MsQuery();
            }
            msq.strquery += " and 1=1 ";
            JObject search = JObject.FromObject(postdata["search"]);
            JArray assetquery = JArray.FromObject(search["assetquery"]);
            if (assetquery.Count != 0)
            {
                msq.strselect += " and " + AssetA1Controller.GetQueryByquerjs(assetquery);
            }
            msq.typecode1 = "nub";//是否显示资产数量
            msq.strselect += " and 1=1 and (ASSET_A1_ISDEL is null or ASSET_A1_ISDEL!='1')";
            DataTable dt = ((DataSet)new BLLasset_a2().Getasset_a2ByQuery(msq).data).Tables[0];
            return JArray.FromObject(dt).ToString();
        }
    }
}